package cc.sheji.controller;


import cc.sheji.Service.DeviceService;
import cc.sheji.Service.MessageCodeService;
import cc.sheji.domain.Device;
import cc.sheji.domain.DeviceQueryCriteria;
import cc.sheji.domain.JsonResult;
import cc.sheji.domain.MessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@CrossOrigin
@RestController
@RequestMapping(value = "/api/v1/messagecode")
public class MessageCodeController {

    @Autowired
    MessageCodeService messageCodeService;

    @RequestMapping("/check")
    public JsonResult check(@RequestParam("code")  String code,@RequestParam("phone")  String phone) throws Exception {
        MessageCode messageCode=new MessageCode();
        messageCode.setCode(code);
        messageCode.setPhone(phone);
        System.out.println("code:"+code);
        return JsonResult.Success(messageCodeService.check(messageCode));
    }

    @PostMapping()
    public JsonResult create(@RequestBody @Validated MessageCode entity) throws Exception {
        entity.setId(null);
        return JsonResult.Success(messageCodeService.create(entity));
    }

}
